package cn.tedu.sp04.order.feignclient;

import java.util.Arrays;
import java.util.List;

import org.springframework.stereotype.Component;

import cn.tedu.sp01.pojo.Item;
import cn.tedu.web.util.JsonResult;
/**
 * 商品列表的降级方法，模拟使用缓存数据
 * @author Administrator
 */
@Component
public class ItemFeignServiceFB implements ItemFeignService{
	@SuppressWarnings("unchecked")
	@Override
	public JsonResult<List<Item>> getItems(String orderId) {
	    //设置50%概率查询缓存数据
		if(Math.random()<0.5) {
			//模拟缓存数据
			return JsonResult.ok().data(
				Arrays.asList(new Item[] {
						new Item(1,"缓存手机商品",2),
						new Item(2,"缓存电脑商品",1),
						new Item(3,"缓存知识的海洋",3),
						new Item(4,"缓存奥特曼玩具",1),
						new Item(5,"缓存喜羊羊玩具",5)				
				})
			);
		}
		//The expression of type JsonResult needs unchecked conversion to conform to JsonResult<List<Item>>
		return JsonResult.err("获取订单商品失败");
	}

	@SuppressWarnings("rawtypes")
	@Override
	public JsonResult decreaseNumber(List<Item> items) {
		return JsonResult.err("修改库存失败");
	}

}
